from django.db import models

class ZhihuContent(models.Model):
    content_id = models.CharField(max_length=64, verbose_name='内容ID', unique=True)
    content_type = models.CharField(max_length=16, verbose_name='内容类型(article | answer | zvideo)')
    content_text = models.TextField(null=True, blank=True, verbose_name='内容文本, 如果是视频类型这里为空')
    content_url = models.CharField(max_length=255, verbose_name='内容落地链接')
    question_id = models.CharField(max_length=64, null=True, blank=True, verbose_name='问题ID, type为answer时有值')
    title = models.CharField(max_length=255, verbose_name='内容标题')
    desc = models.TextField(null=True, blank=True, verbose_name='内容描述')
    created_time = models.CharField(max_length=32, verbose_name='创建时间')
    updated_time = models.CharField(max_length=32, verbose_name='更新时间')
    voteup_count = models.IntegerField(default=0, verbose_name='赞同人数')
    comment_count = models.IntegerField(default=0, verbose_name='评论数量')
    source_keyword = models.CharField(max_length=64, null=True, blank=True, verbose_name='来源关键词')
    user_id = models.CharField(max_length=64, verbose_name='用户ID')
    user_link = models.CharField(max_length=255, verbose_name='用户主页链接')
    user_nickname = models.CharField(max_length=64, verbose_name='用户昵称')
    user_avatar = models.CharField(max_length=255, verbose_name='用户头像地址')
    user_url_token = models.CharField(max_length=255, verbose_name='用户url_token')
    add_ts = models.BigIntegerField(verbose_name='记录添加时间戳')
    last_modify_ts = models.BigIntegerField(verbose_name='记录最后修改时间戳')
    task_id = models.CharField(max_length=255, verbose_name='任务ID')

    class Meta:
        db_table = 'zhihu_content'
        verbose_name = '知乎内容（回答、文章、视频）'
        indexes = [
            models.Index(fields=['content_id'], name='idx_zhihu_content_content_id'),
            models.Index(fields=['created_time'], name='idx_zhihu_content_created_time'),
        ]

class ZhihuComment(models.Model):
    comment_id = models.CharField(max_length=64, verbose_name='评论ID')
    parent_comment_id = models.CharField(max_length=64, null=True, blank=True, verbose_name='父评论ID')
    content = models.TextField(verbose_name='评论内容', null=True, blank=True)
    publish_time = models.CharField(max_length=32, verbose_name='发布时间')
    ip_location = models.CharField(max_length=64, null=True, blank=True, verbose_name='IP地理位置')
    sub_comment_count = models.IntegerField(default=0, verbose_name='子评论数')
    like_count = models.IntegerField(default=0, verbose_name='点赞数')
    dislike_count = models.IntegerField(default=0, verbose_name='踩数')
    content_id = models.ForeignKey(
        ZhihuContent,
        to_field='content_id',
        db_column='content_id',
        on_delete=models.CASCADE,
        related_name='comments',
        verbose_name='文章关联',
        null=True,
        blank=True,
    )
    content_type = models.CharField(max_length=16, verbose_name='内容类型(article | answer | zvideo)')
    user_id = models.CharField(max_length=64, verbose_name='用户ID')
    user_link = models.CharField(max_length=255, verbose_name='用户主页链接')
    user_nickname = models.CharField(max_length=64, verbose_name='用户昵称')
    user_avatar = models.CharField(max_length=255, verbose_name='用户头像地址')
    add_ts = models.BigIntegerField(verbose_name='记录添加时间戳')
    last_modify_ts = models.BigIntegerField(verbose_name='记录最后修改时间戳')

    class Meta:
        db_table = 'zhihu_comment'
        verbose_name = '知乎评论'
        indexes = [
            models.Index(fields=['comment_id'], name='idx_zhihu_comment_comment_id'),
            models.Index(fields=['content_id'], name='idx_zhihu_comment_content_id'),
            models.Index(fields=['publish_time'], name='idx_zhihu_comment_publish_time'),
        ]


class ZhihuCreator(models.Model):
    user_id = models.CharField(max_length=64, unique=True, verbose_name='用户ID')
    user_link = models.CharField(max_length=255, verbose_name='用户主页链接')
    user_nickname = models.CharField(max_length=64, verbose_name='用户昵称')
    user_avatar = models.CharField(max_length=255, verbose_name='用户头像地址')
    url_token = models.CharField(max_length=64, verbose_name='用户URL Token')
    gender = models.CharField(max_length=16, null=True, blank=True, verbose_name='用户性别')
    ip_location = models.CharField(max_length=64, null=True, blank=True, verbose_name='IP地理位置')
    follows = models.IntegerField(default=0, verbose_name='关注数')
    fans = models.IntegerField(default=0, verbose_name='粉丝数')
    anwser_count = models.IntegerField(default=0, verbose_name='回答数')
    video_count = models.IntegerField(default=0, verbose_name='视频数')
    question_count = models.IntegerField(default=0, verbose_name='问题数')
    article_count = models.IntegerField(default=0, verbose_name='文章数')
    column_count = models.IntegerField(default=0, verbose_name='专栏数')
    get_voteup_count = models.IntegerField(default=0, verbose_name='获得的赞同数')
    add_ts = models.BigIntegerField(verbose_name='记录添加时间戳')
    last_modify_ts = models.BigIntegerField(verbose_name='记录最后修改时间戳')
    task_id = models.CharField(max_length=255, verbose_name='任务ID', null=True, blank=True)

    class Meta:
        db_table = 'zhihu_creator'
        verbose_name = '知乎创作者'
        indexes = [
            models.Index(fields=['user_id'], name='idx_zhihu_creator_user_id'),
        ]
